﻿//*********************************************************
//把代码中带“”的固定字符放到xml里面
//*********************************************************

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace 字符串
{
    public partial class String1 : Form
    {
        StringBuilder sb;

        public String1()
        {
            InitializeComponent();
            sb = new StringBuilder();
        }

        private void String1_Load(object sender, EventArgs e)
        {
            this.comboBox1.SelectedIndex = 0;
        }

        private void zhengze(string source)
        {
            Regex r = new Regex("\".*?\"");
            Match m = r.Match(source);
            string s = "";

            while (m.Success)
            {
                s = m.Value.ToString();
                s = s.Substring(s.IndexOf("\"") + 1, s.LastIndexOf("\"") - s.IndexOf("\"") - 1);
                sb.Append(s + "\n\n");

                string s2;

                //s2 = s.Replace(".","");

                s2 = s.Replace("(", "");

                s2 = s2.Replace(")", "");

                s2 = s2.Replace(" ", "");

                //if (s.IndexOf(" ") != -1)
                //{
                //    s2 = s2.Substring(0, s.IndexOf(" ")) == "" ? s : s.Substring(0, s.IndexOf(" "));
                //}

                string s1 = "Milpa.Device.UI.Common.GlobalizationTransition.TransferString(\"" + this.comboBox1.SelectedItem + s2 + "\")";

                sb.Append(s1 + "\n");

                sb.Append("<data name=\"" + this.comboBox1.SelectedItem + s2 + "\" xml:space=\"preserve\">\n");
                sb.Append("<value>" + s + "</value>\n");
                sb.Append("</data>");
                sb.Append("\n");
                sb.Append("\n");

                m = m.NextMatch();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s = "";
            string s1 = this.richTextBox1.Text;
            char[] split = new char[] { '\n' };
            string[] temp = s1.Split(split);

            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i].Trim().Length > 2)
                {
                    if (!temp[i].Trim().Substring(0, 2).Equals("//"))
                    {
                        if (temp[i].IndexOf("\"") != -1)
                        {
                            zhengze(temp[i]);
                        }
                    }
                }
            }

            this.richTextBox2.Text = sb.ToString();
            sb.Length = 0;
        }
    }
}